﻿#include "../import/head.h"
#include "main_wnd.h"
#include "../data_struct/head.h"
#include "../global/head.h"
#include "../macro/head.h"
#include "../msg/head.h"

namespace xos_sgsj
{
    main_wnd::main_wnd( QWidget *parent )
        : QMainWindow( parent )
    {
		ui.setupUi( this );
		init_ui();
    }

    main_wnd::~main_wnd()
    {
    }

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// 
	// 初始化
	// 

	int main_wnd::init_ui()
	{
		int ret = 0;

		QAction *openAction = 0;

		openAction = new QAction( QIcon( ":/res/doc-open" ), tr( "&Open" ), this );
		openAction->setShortcut( QKeySequence::Open );
		openAction->setStatusTip( tr( "open an existing file" ) );
		connect( openAction, &QAction::triggered, this, &main_wnd::open );

		QMenu * file = menuBar()->addMenu( tr( "&File" ) );
		file->addAction( openAction );

		QToolBar * tool = addToolBar( tr( "&File" ) );
		tool->addAction( openAction );

		statusBar();

		return ret;
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// 
	// 消息处理
	// 

	void main_wnd::closeEvent( QCloseEvent *event )
	{
		int ret = 0;

		if( ( 0 == ret ) && g_pSysData->m_bQuiting && g_pSysData->m_bQuit )
		{
			event->accept();
			ret = 1;
		}

		if( 0 == ret )
		{
			g_pSysData->m_bQuiting = true;
			event->ignore();
		}

		if( 0 == ret )
		{
			xos_sgsj::data * p = g_pSysData->m_pPool->m_data_pool.GetItem();
			p->init();
			p->m_nMsg = MSG_USER_QUIT;
			g_pSysData->notify( p );
			p = 0;
		}
	}

	void main_wnd::open()
	{
		QMessageBox::information( this, tr( "information" ), tr( "open" ) );
	}

}
